package com.xyh.transaction.common;

import com.xyh.transaction.entity.LoginUser;
import com.xyh.transaction.entity.Permission;
import com.xyh.transaction.entity.User;
import com.xyh.transaction.utils.ImageUtils;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;

import java.util.ArrayList;

public class Current {

    public static LoginUser getCurrentUser() {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (authentication != null && authentication.getPrincipal() instanceof LoginUser) {
            return (LoginUser) authentication.getPrincipal();
        }

        // 游客登录
        LoginUser loginUser = new LoginUser();
        User user = new User();
        user.setId(0);
        user.setUsername("游客");
//        loginUser.setPermissions(new ArrayList<>());
//        loginUser.getPermissions().add(new Permission(1,"Read"));
        loginUser.setUser(user);
        return loginUser;
    }
}
